package day7;

public class Phone {
    private String type;
    private String color;
    private double price;
    //设置属性方法  setXxx(参数)  不需要返回值
    public void setType(String type) {
        //this.type = type;
        //手机型号：安卓  IOS   鸿蒙
        String[] types={"安卓","IOS","鸿蒙"};
        boolean b=false;
        for(String t:types){
            if(t.equals(type)){
                b=true;
                break;
            }
        }
        if(b){
            this.type=type;
        }else{
            System.out.println("你手机的型号不合法");
            this.type="安卓";
        }
    }
    public String getType() {
        return type;
    }

    //获取属性  getXxx()   一定需要返回值  根据属性类型返回值
    public String getColor() {
        return color;
    }

    public void setColor(String color) {
        if("黑色".equals(color)||"颜色".equals(color)){
            this.color=color;
        }
        else{
            System.out.println("传入颜色不合法");
            this.color = "黑色";
        }

    }

    public double getPrice() {
        return price;
    }

    public void setPrice(double price) {
        if(price>=1000&&price<=5000){
            this.price=price;
        }
        else{
            System.out.println("传入价格不合法");
            this.price = 1000;
        }
    }


    public void print(){
        System.out.println("型号："+type);
        System.out.println("颜色："+color);
        System.out.println("价格："+price+"元");
    }

}

class TestPhone {
    public static void main(String[] args) {
        Phone phone = new Phone();
        phone.setType("aaaa");
        phone.setColor("bbbb");
        phone.setPrice(12000);
        phone.print();
    }
}
